package Threadprojects.pro2_knn.test;

import Threadprojects.pro2_knn.bean.BankMarketing;
import Threadprojects.pro2_knn.grounp2.PGKClassfier;
import Threadprojects.pro2_knn.util.BankMarketingLoader;

import java.util.List;

public class test_pool {
    public static void main(String[] args) {
        List<BankMarketing> bank = BankMarketingLoader.load("src/main/java/Threadprojects/pro2_knn/data/bank.data");

        System.out.println(bank.size());
        List<BankMarketing> test = BankMarketingLoader.load("src/main/java/Threadprojects/pro2_knn/data/bank.test");

        System.out.println(test.size());

        int k = 10;
        if (args!=null&&args.length>0){
            k=Integer.parseInt(args[0]);
        }
        int success=0,mistakes=0;
        int numThreads=Runtime.getRuntime().availableProcessors();
        PGKClassfier classfier = new PGKClassfier(k, numThreads, true, test);
        long start=System.currentTimeMillis();
        for (BankMarketing testData : test) {
            String tag=classfier.classfier(testData);
            if (tag.equals(testData.getTag())){
                success++;
            }else {
                mistakes++;
            }
        }
        long end=System.currentTimeMillis();

        System.out.println("计算时间"+(end-start));
        System.out.println("成功"+success+"失败"+mistakes+"正确率"+(((double)success/(success+mistakes))*100)+"%");
    }
}
